<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
        <h1>test</h1>
	</body>
    <script type="text/javascript">
        // this 指向
        /*
        var length = 10;
        function fn() {
            console.log(this.length);
        }

        var obj = {
        length: 5,
        method: function(fn) {
            fn();//10
            arguments[0]();//2
        }
        };

        obj.method(fn, 1);
        */
        //变量提升
        /*
        (function () {
            try {
                throw new Error();
            } catch (x) {
                var x = 1, y = 2;
                console.log('x1',x);//1
            }
            console.log('x2',x);//undefined
            console.log('y2',y);//2
        })();
        */
        
        // js解析 真为1 假为0
        /*
        console.log(1 < 2 < 3);
        console.log(3 > 2 > 1);
        */
        

        //  JS小数计算不准确的bug
        /*
        console.log(0.1+0.2 == 0.3)//false
        console.log(0.1 + 0.2);//0.30000000000000004
        */

        // console.log(Math.round(1.3))
        // console.log(Math.floor(Math.random(1.6)*10+1))
        // console.log(Math.floor(1.7))
        // console.log(Math.ceil(1.2))
        

        // 将obj变成链表格式
        /*
        var obj = [
            {id:1,parent:null},
            {id:2,parent:2},
            {id:3,parent:3},
            {id:4,parent:4}
        ];
        var o={};
        function test(o,obj){
            for(let i=0;i<obj.length;i++){
                if(!o.child){
                    o.id = obj[i].id;
                    o.parent = obj[i].parent
                    if(obj[i+1]){
                        o.child = {}
                    }
                }else{
                    obj.shift()
                    test(o.child,obj)
                }
            }
        }
        test(o,obj)
        console.log('o',o)
        */
        
        // 堆栈溢出
        /*
        function isEven (num) {
            if (num === 0) {
                return true;
            }

            if (num === 1) {
                return false;
            }

            // return isEven(Math.abs(num) - 2);
            return function(){
                return isEven(Math.abs(num) - 2);
            }
        }
        
        console.log(isEven(100000)()())
        */

        // 对象的key值只能是string
        /*
        var a={};
        var b={key:'b'},
        c={key:'c'};
        a[b]=123;//a['object object']
        a[c]=456;//a['object object']
        console.log(a)
        console.log(a[b]);//456
        */
	</script>
</html>
